package com.netx.cubigraf.apps.zipper;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import com.netx.generics.io.ProgressObserver;


public class ProgressBarObserver extends ProgressObserver {

	private final double _totalBytes;
	private final Label _label;
	private final ProgressBar _pBar;
	
	public ProgressBarObserver(long totalBytes, ProgressBar pBar, Label label) {
		super();
		_totalBytes = totalBytes;
		_label = label;
		_pBar = pBar;
		_pBar.setMaximum((int)(totalBytes/1000));
	}
	
	public void increment(long inc) {
		super.increment(inc);
		_pBar.setSelection((int)(getProgress()/1000));
		double percComplete = (new Double(getProgress()) / _totalBytes)*100;
		_label.setText(Math.round(percComplete)+" %");
	}
}
